import { AxiosPromise } from "axios";
import request from "@/utils/request";
import {
  AddLinkStudentData,
  AddStudentData,
  DeleteStudentData,
  StudentPageVO,
  StudentQuery,
} from "./types";

/**
 * 学生分页列表
 *
 * @param queryParams
 */
export function getStudentPage(
  queryParams: StudentQuery,
  courseId: number
): AxiosPromise<PageResult<StudentPageVO[]>> {
  return request({
    url: "/api/v1/system/course/students",
    method: "get",
    params: {
      ...queryParams,
      courseId,
    },
  });
}

/**
 * 删除学生
 *
 * @param queryParams
 */
export function DeleteStudent(
  queryParams: DeleteStudentData,
  courseId: number
): AxiosPromise<void> {
  return request({
    url: "/api/v1/system/user/class/remove",
    method: "delete",
    params: { ...queryParams, courseId },
  });
}

/**
 * 批量删除学生
 *
 * @param queryParams
 */
export function DeleteStudents(
  queryParams: DeleteStudentData[],
  courseId: number
): AxiosPromise<void> {
  return request({
    url: "/api/v1/system/user/class/deleteStudents",
    method: "delete",
    params: {
      courseId,
    },
    data: queryParams,
  });
}

/**
 * 添加学生 生成链接
 *
 * @param queryParams
 */
export function AddLinkStudent(
  queryParams: AddLinkStudentData,
  courseId: number
): AxiosPromise<string> {
  return request({
    url: "/api/v1/system/user/class/createLink",
    method: "get",
    params: {
      ...queryParams,
      courseId,
    },
  });
}

/**
 * 点击链接添加学生
 *
 * @param key
 */
export function JoinLinkStudent(key: string): AxiosPromise<string> {
  return request({
    url: "/api/v1/system/user/class/parse?key=" + key,
    method: "get",
  });
}

/**
 * 把学生加入课程
 *
 * @param key
 */
export function AddStudent(key: string): AxiosPromise<string> {
  return request({
    url: "/api/v1/system/user/class/invite?key=" + key,
    method: "post",
  });
}

/**
 * 添加学生 直接添加
 *
 * @param queryParams
 */
export function DirectAddStudent(
  queryParams: AddStudentData,
  courseId: number
): AxiosPromise<string> {
  return request({
    url: "/api/v1/system/user/class/add",
    method: "post",
    params: {
      ...queryParams,
      courseId,
    },
  });
}

/**
 * 获取班级信息
 *
 * @param queryParams
 */
export function getclasslist(courseId: number) {
  return request({
    url: "/api/v1/system/class/course/list",
    method: "get",
    params: {
      courseId,
    },
  });
}

/**
 * 获取规则信息
 *
 * @param queryParams
 */
export function getrulelist(courseId: number) {
  return request({
    url: "/api/v1/system/class/course/list",
    method: "get",
    params: {
      courseId,
    },
  });
}
